const db = require('../db/index')


//成绩录入逻辑处理
exports.addPerformance = (req,res) => {
    const userinfo = req.body
    const sql = 'insert into performance set ?'
    db.query(sql,{sno:userinfo.sno, number:userinfo.number, coursename:userinfo.coursename, achievement:userinfo.achievement, data:userinfo.data, username:userinfo.username,credit:userinfo.credit})
        .then(([results,fields])=>{
            res.send({message:"学习课程成功!!!",code:200})
        }).catch(reason => {
        res.send(reason)
    })
}

//指定成绩获取逻辑处理
exports.getPerformance = (req,res) => {
    const sql = 'select * from performance where username = ?'
    db.query(sql,[req.query.username]).then(([results,fields])=>{
        res.send(results)
    }).catch(reason => {
        res.send(reason)
    })
}

//所有成绩获取逻辑处理
exports.getPerformances = (req,res) => {
    const sql = 'select * from performance '
    db.query(sql).then(([results,fields])=>{
        res.send(results)
    }).catch(reason => {
        res.send(reason)
    })
}

//添加成绩信息逻辑处理
exports.updateperformance = (req,res) => {
    console.log()
    const sql = `update performance set achievement=${req.body.achievement} where id =${req.body.id}`
    db.query(sql).then(([results,fields])=>{
        res.send({message:"成绩更新成功!!!",code:200})
    }).catch(reason => {
        res.send(reason)
    })
}

//删除成绩逻辑处理
exports.deletePerformance = (req,res) => {
    const sql = 'delete from performance where number = ?'
    db.query(sql,req.body).then(([results,fields])=>{
        res.send({message:"删除课程成功!!!",code:200})
    }).catch(reason => {
        res.send(reason)
    })
}